#include "Object.h"
#include "Class.h"
#include "Class.h"
Class* Object::getClass(Image* img){
   if(this==NULL){
       return img->clsNull;
   }else{
       Class* cls= (Class*)vptr[0].method;
       //printf("Class is %s.\n",((Class*)cls)->getName().c_str());
       return cls;
   }
}
void* Object::dataAt(int offset){
   char* me=(char*)this;
   me+=offset;
   return me;
}
Object* Object::send(Image* image,string selector,int argc,Object** argv){
    if(this==NULL){
        //printf("Undefined object\n");
       Object* r= image->clsNull->sendClass(this,selector,argc,argv);
       return r;
    }else{
       Object* r= getClass(image)->sendClass(this,selector,argc,argv);
       return r;
    }
}
bool Object::isKindOf(Class* cls){
    //getClass();
    if(this==NULL) return false;
    return vptr==cls->clsVptr;
}
void Object::set(string field,Object* value){
    if(this!=NULL){
        getClass(NULL)->set(this,field,value);
    }else{
        
    }
}
Object* Object::get(string field){
    if(this!=NULL){
        return getClass(NULL)->get(this,field);
    }else{
        return NULL;
    }
}
